package com.pzj.swtcallcom.ocx.ie;

import org.eclipse.swt.SWT;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Shell;

public class OutIEPlayer {

	/**
	 * @param args
	 * @throws InterruptedException
	 */
	public static void main(String[] args) throws InterruptedException {
		Shell shell = new Shell(SWT.CLOSE | SWT.MIN);
		IEFrame ieFrame = new IEFrame(shell, SWT.NONE);
//		String url = System.getProperty("user.dir") + "\\test.html";
		String[] methodName = new String[] { "Navigate", "URL" };
		Variant[] rgvarg = new Variant[1];
		rgvarg[0] = new Variant("http://www.google.com.hk");
		ieFrame.executes(methodName, rgvarg);

		Variant vdoc = ieFrame.getProperty("document");// 获取ie的Document元素
		OleAutomation doc = vdoc.getAutomation();// 转成ole
		Variant vplayer = doc.invoke(
				doc.getIDsOfNames(new String[] { "getElementById" })[0],
				new Variant[] { new Variant("play") });
		Thread.sleep(3000);
		// 登录模拟click
		vplayer.getAutomation()
				.invoke(vplayer.getAutomation().getIDsOfNames(
						new String[] { "click" })[0]);
		// 获取listinfo元素
		Variant VtextArea = doc.invoke(
				doc.getIDsOfNames(new String[] { "getElementById" })[0],
				new Variant[] { new Variant("listinfo") });
		OleAutomation textArea = VtextArea.getAutomation();
		// 获取value属性的id
		int listinfoID = textArea.getIDsOfNames(new String[] { "value" })[0];
		// 获取内容
		Variant list = textArea.getProperty(listinfoID);
		System.out.println(": " + list.getString());
	}

}
